<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>书籍展示页面</title>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap HelloWorld</title>

    <!-- Bootstrap -->
    <link href="../../bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="../../bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="../../bootstrap/js/jquery-3.4.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="../../bootstrap/js/bootstrap.min.js"></script>

    <script>
        $(function () {
            /*var user = '

            ${sessionScope.get("user")}';
            console.log(user);*/
        })
    </script>

</head>
<body>

<div class="container">
    <div class="row">
        <div class="col-md-10 colum">
            <div class="page-header">
                <h1>
                    <strong>书籍管理系统</strong>
                </h1>
            </div>
        </div>
        <div class="dropdown">
            <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="true">
                ${sessionScope.get("user").userName}
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" style="left: 81%" aria-labelledby="dropdownMenu1">
                <li><a href="${pageContext.request.contextPath}/user/queryUserByName/${user.userName}">个人信息</a></li>
                <li><a href="${pageContext.request.contextPath}/user/toUpdate/${user.userName}">修改信息</a></li>
                <li role="separator" class="divider"></li>
                <li><a href="${pageContext.request.contextPath}/user/tologin">退出</a></li>
            </ul>
        </div>


        <div class="row">
            <div class="col-md-4 colum">
                <%--toAddBook--%>
                <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/toAddBook">新增书籍</a>
                <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/showBook">显示全部书籍</a>
            </div>
            <div class="col-md-8 colum">
                <%--查询书籍--%>
                <form action="${pageContext.request.contextPath}/book/queryBookById" method="post" style="float: right">
                    <input type="text" name="bookID" class="form-control" placeholder="请输入要查询的书籍id">
                    <input type="submit" value="查询" class="btn btn-primary">
                </form>
                <form action="${pageContext.request.contextPath}/book/queryBookByName" method="post"
                      style="float: right">
                    <input type="text" name="bookName" class="form-control" placeholder="请输入要查询的书籍名称">
                    <input type="submit" value="查询" class="btn btn-primary">
                </form>
            </div>
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-12 colum">
            <table class="table table-hover table-striped">
                <thead>
                <tr>
                    <th>书籍编号</th>
                    <th>书籍名称</th>
                    <th>书籍数量</th>
                    <th>书籍价格</th>
                    <th>书籍详情</th>
                    <th>操作</th>
                </tr>
                </thead>
                <%--书籍从数据库中查询出来，从这个list中遍历出来：foreach--%>
                <tbody>
                <c:forEach var="book" items="${pageInfo.list}">
                    <tr>
                        <td>${book.bookID}</td>
                        <td>${book.bookName}</td>
                        <td>${book.bookCounts}</td>
                        <td>${book.bookPrice}</td>
                        <td>${book.detail}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/book/toUpdate?id=${book.bookID}">修改</a>
                            &nbsp; | &nbsp;
                            <a href="${pageContext.request.contextPath}/book/deleteBook/${book.bookID}">删除</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <div>
                <nav aria-label="Page navigation example">
                    <ul class="pagination justify-content-center">
                        <li class="page-item disabled">
                            <a class="page-link"
                               href="${pageContext.request.contextPath}/book/showBook?page=${pageInfo.pageNum-1}"
                               tabindex="-1" aria-disabled="true">Previous</a>
                        </li>
                        <li class="page-item"><a class="page-link"
                                                 href="${pageContext.request.contextPath}/book/showBook?page=1">1</a>
                        </li>
                        <li class="page-item"><a class="page-link"
                                                 href="${pageContext.request.contextPath}/book/showBook?page=2">2</a>
                        </li>
                        <li class="page-item"><a class="page-link"
                                                 href="${pageContext.request.contextPath}/book/showBook?page=3">3</a>
                        </li>
                        <li class="page-item">
                            <a class="page-link"
                               href="${pageContext.request.contextPath}/book/showBook?page=${pageInfo.pageNum+1}">Next</a>
                        </li>
                    </ul>
                </nav>
            </div>

        </div>
    </div>
</div>
</body>
</html>
